/*
 * EquilibriumConstantData.cpp
 *
 *  Created on: 31 Jul 2011
 *      Author: Allan
 */

#include "EquilibriumConstantData.h"

// C++ includes
#include <cmath>

// GeoReact includes
#include "NumericalUtilities.h"

EquilibriumConstantData::EquilibriumConstantData() :
logKi(1, 0.0), Ti(1, 25.0), knownFunctional(false)
{}

EquilibriumConstantData::EquilibriumConstantData(double logK) :
logKi(1, logK), Ti(1, 25.0), knownFunctional(false)
{}

EquilibriumConstantData::EquilibriumConstantData(double logK, double T) :
logKi(1, logK), Ti(1, T), knownFunctional(false)
{}

EquilibriumConstantData::EquilibriumConstantData(const vector<double>& logKi, const vector<double>& Ti) :
logKi(logKi), Ti(Ti), knownFunctional(false)
{}

EquilibriumConstantData::EquilibriumConstantData(const std::function<const double(double T, double P)>& K)
{
	this->K = K;
	
	knownFunctional = true;
}

void EquilibriumConstantData::GetData(vector<double>& logKi, vector<double>& Ti) const
{
	logKi = this->logKi;
	Ti = this->Ti;
}

const double EquilibriumConstantData::operator()(double T, double P) const
{
	if(knownFunctional)
		return K(T, P);
	else
	{
		const double logK = LagrangeInterpolation(T, &Ti[0], &logKi[0], Ti.size());
	
		return std::pow(10.0, logK);
	}
}
